<%@ page import="org.clipjoint.enums.GameTypeEnum" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="${ bp }/static/layui/css/layui.css">
    <style type="text/css">
        .layui-form-select {
            z-index: 99999 !important;
        }
    </style>
</head>

<body>
<div class="layui-container">

    <%-- 添加表单 --%>
    <form class="layui-form" style="margin-top: 50px;">
        <div class="layui-form-item">
            <label class="layui-form-label">游戏id</label>
            <div class="layui-input-block">
                <input type="text" name="game_id" lay-verify="required" lay-reqText="游戏id不能为空" autocomplete="off"
                       placeholder="请输入游戏id" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">密钥</label>
            <div class="layui-input-block">
                <input type="text" name="keyword" lay-verify="required" lay-reqText="密钥不能为空" autocomplete="off"
                       placeholder="请输入密钥" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-block">
                <input type="text" name="detail" lay-verify="required" lay-reqText="状态不能为空" autocomplete="off"
                       placeholder="请输入状态" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label"></label>
            <div class="layui-input-block">
                <button type="button" class="layui-btn" lay-submit lay-filter="add">添加</button>
                <button type="reset" class="layui-btn layui-btn-danger">清空</button>
            </div>
        </div>
    </form>

</div>

<script type="text/javascript" src="${ bp }/static/layui/layui.all.js"></script>
<script src="https://unpkg.com/wangeditor/dist/wangEditor.min.js"></script>
<script type="text/javascript">
    layui.use(['form', 'layer', 'jquery', 'upload'], function () {
        let form = layui.form;
        let layer = layui.layer;
        let $ = layui.jquery;
        let upload = layui.upload;


        // 监听添加表单提交
        form.on('submit(add)', function (data) {

            // 使用ajax请求接口
            $.ajax({
                url: '${ bp }/keyword?method=add',
                type: 'post',
                data: data.field,
                dataType: 'json',
                success: (result) => {
                    if (result.code === 0) {
                        layer.msg('添加成功', {
                            time: 1000,
                            icon: 1
                        }, function () {
                            // 关闭窗口
                            parent.layer.close(parent.layer.getFrameIndex(window.name));
                            // 刷新对应模块的table
                            parent.document.getElementById('秘钥管理').contentWindow.layui.table.reload('table');
                        });
                    } else {
                        layer.msg(result.msg, {
                            time: 2000,
                            icon: 2
                        });
                    }
                },
                error: () => {
                    console.log('请求接口错误');
                }
            });


        });

    });
</script>

</body>
</html>
